﻿using System;
using System.Windows.Forms;
using Me.Amon.Properties;
using Me.Amon.Util;

namespace Me.Amon.WMS.V
{
    public partial class UcLogin : UserControl, IAuth
    {
        private Main _Main;

        public UcLogin()
        {
            InitializeComponent();
        }

        #region 接口实现
        public Control Control
        {
            get { return this; }
        }

        public void Init(Main main)
        {
            _Main = main;
        }
        #endregion

        private void BtUpdate_Click(object sender, EventArgs e)
        {
            var user = TbUser.Text.Trim();
            if (string.IsNullOrEmpty(user))
            {
                MessageBox.Show("请输入用户！");
                TbUser.Focus();
                return;
            }
            if (!CharUtil.IsValidate(user, 3, 32))
            {
                MessageBox.Show("用户格式输入错误！");
                TbPass.Text = "";
                TbUser.Focus();
                return;
            }

            var pass = TbPass.Text.Trim();
            if (string.IsNullOrEmpty(pass))
            {
                MessageBox.Show("请输入密码！");
                TbUser.Focus();
                return;
            }
            TbPass.Text = "";
            if (!CharUtil.IsValidate(pass, 3, 32))
            {
                MessageBox.Show("密码格式输入错误！");
                TbPass.Focus();
                return;
            }

            var setting = Settings.Default;

            // 首次登录
            //if (string.IsNullOrWhiteSpace(setting.Server))
            //{
            //    MessageBox.Show("系统配置错误，请与管理员联系！");
            //    return;
            //}

            // 正常登录
            //var data = string.Format("{0}/POS/Emp.ashx?t={1}&{2}={3}&{4}={5}&{6}={7}",
            //    setting.Server, setting.Code,
            //    CObj.PARAM_KEY_CORP, setting.Corp,
            //    CObj.PARAM_KEY_SHOP, setting.Shop,
            //    CObj.PARAM_KEY_USER, user);

            //var rest = WebUtil.POST(data, HashUtil.Password(pass));

            _Main.Visible = false;
            var wms = new WWms();
            wms.Show();
        }

        private void BtCancel_Click(object sender, EventArgs e)
        {
            _Main.Close();
        }
    }
}
